#!/usr/bin/env python3
"""
Example usage of high accuracy OCR models
"""

import os
import sys

# Add parent directory to path to import modules
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from config.settings import settings
from services.ocr_service import OCRService

def example_high_accuracy_configuration():
    """Example of configuring high accuracy models"""
    print("=== High Accuracy Model Configuration ===")
    
    # Method 1: Using environment variables (set before starting the application)
    print("1. Environment Variable Configuration:")
    print("   export OCR_USE_HIGH_ACCURACY=true")
    print("   python main.py")
    print()
    
    # Method 2: Programmatic configuration
    print("2. Programmatic Configuration:")
    print("   from config.settings import settings")
    print("   settings.OCR_USE_HIGH_ACCURACY = True")
    print()
    
    # Show current configuration
    print(f"Current high accuracy setting: {settings.OCR_USE_HIGH_ACCURACY}")
    print()

def example_model_initialization():
    """Example of initializing OCR service with high accuracy models"""
    print("=== OCR Service Initialization with High Accuracy Models ===")
    
    # Configure for high accuracy
    original_setting = settings.OCR_USE_HIGH_ACCURACY
    settings.OCR_USE_HIGH_ACCURACY = True
    
    try:
        # Initialize OCR service
        ocr_service = OCRService()
        print("Initializing OCR service with high accuracy models...")
        ocr_service.initialize()
        print("OCR service initialized successfully!")
        
        if ocr_service.is_healthy():
            print("OCR service is healthy and ready for high accuracy processing")
        else:
            print("OCR service initialization failed")
            
    except Exception as e:
        print(f"Error initializing OCR service: {e}")
    finally:
        # Restore original setting
        settings.OCR_USE_HIGH_ACCURACY = original_setting

def example_performance_considerations():
    """Example of performance considerations with high accuracy models"""
    print("\n=== Performance Considerations ===")
    print("High accuracy models provide better recognition but require more resources:")
    print("1. Memory usage: 2-3x higher")
    print("2. Processing time: 2-3x longer")
    print("3. Disk space: Additional 1-2GB for model files")
    print()
    print("Best practices:")
    print("- Use high accuracy models for critical document processing")
    print("- Use standard models for real-time applications")
    print("- Monitor resource usage in production")
    print("- Test accuracy improvements with your specific use case")

def example_api_usage():
    """Example of API usage with high accuracy models"""
    print("\n=== API Usage Examples ===")
    print("To enable high accuracy models via API:")
    print()
    print("1. Set environment variable:")
    print("   OCR_USE_HIGH_ACCURACY=true")
    print()
    print("2. Start the server:")
    print("   python main.py")
    print()
    print("3. Use the API as usual - higher accuracy will be applied automatically")
    print()
    print("Example curl command:")
    print("curl -X POST \"http://localhost:8001/api/ocr/recognize\" \\")
    print("     -H \"accept: application/json\" \\")
    print("     -H \"Content-Type: multipart/form-data\" \\")
    print("     -F \"file=@document.jpg\"")

if __name__ == "__main__":
    print("High Accuracy OCR Models Examples")
    print("=" * 40)
    
    example_high_accuracy_configuration()
    example_model_initialization()
    example_performance_considerations()
    example_api_usage()
    
    print("\nFor more detailed information, see:")
    print("- HIGH_ACCURACY_MODELS.md")
    print("- README.md")